home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 140 / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan).7z / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan) (Track 1).bin / tools / dshell / dsh333bs.lzh / mesh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-11  |  3.4 KB  |  204 lines

  1. /*
  2.     dshell    v3
  3.  
  4.     背景にスケールを描く
  5. */
  6.  
  7. #include    "dsh.h"
  8.  
  9.  
  10. static void disp_mesh_item(const char **);
  11. static void mesh_exec(short , short , short );
  12.  
  13.  
  14. #define        ITEMS        6
  15. #define        WIN_SX        34
  16. #define        WIN_SY        24
  17. #define        MAX_MESLEN    6
  18.  
  19.  
  20. /*
  21.     メッシュメニューの表示する
  22. */
  23. static void 
  24. disp_mesh_item(const char **ptr)
  25. {
  26.     int i;
  27.  
  28.     for (i = 0; i < ITEMS; i++) {
  29.         B_LOCATE(WIN_SX, WIN_SY + i);
  30.         B_PRINT(ptr[i]);
  31.     }
  32. }
  33.  
  34.  
  35.  
  36. void 
  37. Menu_mesh()
  38. {
  39.     int dmx, dmy, mbl, mbr, mx, my;
  40.     int ty, oty;
  41.     static short x_style = 0x0000, y_style = 0x0000;    /* x,yのラインスタイル初期値 */
  42.  
  43.     static const char *menu[ITEMS] =
  44.     {
  45.         "横直線",
  46.         "横破線",
  47.         "縦直線",
  48.         "縦破線",
  49.         "線消去",
  50.         " 終了 "
  51.     };
  52.  
  53.     tbox_w2(WIN_SX, WIN_SY, WIN_SX + MAX_MESLEN, WIN_SY + ITEMS);
  54.     msarea(WIN_SX * 8, WIN_SY * 16, (WIN_SX + MAX_MESLEN) * 8, (WIN_SY + ITEMS) * 16 - 4);
  55.  
  56.     /*
  57.     !    メニュー表示
  58.     */
  59.     B_COLOR(3);
  60.     disp_mesh_item(menu);
  61.  
  62.     /*
  63.     !    マウスなど離されるの待ち
  64.     */
  65.     wait_mb_off();
  66.  
  67.     oty = -1;        /* 古い座標なんてもってないから */
  68.     while (1) {
  69.  
  70.         dmsstat(&dmx, &dmy, &mbl, &mbr);
  71.         dmspos(&mx, &my);
  72.         p_time(0);
  73.  
  74.         /*
  75.         !    ライトダウンで終了
  76.         */
  77.         if (mbr == -1) {
  78.             break;
  79.         }
  80.         /*
  81.         !    レフトダウンで実行
  82.         */
  83.         if (oty != -1 && mbl == -1) {
  84.             short lflag = 0;
  85.  
  86.             /*
  87.             !    セレクトされているメニューの実行
  88.             !    パラメータセットの場所
  89.             */
  90.             switch (oty) {
  91.             case 0:
  92.                 y_style = 0xFFFF;
  93.                 lflag = 2;
  94.                 break;
  95.             case 1:
  96.                 y_style = 0xCCCC;
  97.                 lflag = 2;
  98.                 break;
  99.             case 2:
  100.                 x_style = 0xFFFF;
  101.                 lflag = 1;
  102.                 break;
  103.             case 3:
  104.                 x_style = 0xCCCC;
  105.                 lflag = 1;
  106.                 break;
  107.             case ITEMS - 2:
  108.             case ITEMS - 1:
  109.             default:
  110.                 break;
  111.             };
  112.  
  113.             /*
  114.             !    実際に処理を振り分けるとこ
  115.             */
  116.             if (oty == ITEMS - 1) {    // 終了
  117.                 break;
  118.             } if (oty == ITEMS - 2) {    // 消去
  119.                 fill(0, 16, 767, 495, 0);
  120.             } else {/* メッシュ実行を選んだか? */
  121.                 mesh_exec(x_style, y_style, lflag);
  122.             }
  123.  
  124.         }
  125.         /*
  126.         !    ヌルイベント
  127.         */
  128.         {
  129.             ty = (my - WIN_SY * 16) / 16;
  130.             if (ty != oty && ty >= 0 && ty < ITEMS) {    /* Y座標が更新されたか? */
  131.                 disp_mesh_item(menu);
  132.                 B_LOCATE(WIN_SX, WIN_SY + ty);
  133.                 B_COLOR(13);
  134.                 B_PRINT(menu[ty]);
  135.                 B_COLOR(3);
  136.             }
  137.             oty = ty;
  138.         }
  139.     }
  140.  
  141.  
  142.     /*
  143.     !    ウィンドウを元に戻す
  144.     */
  145.     msarea(0, 0, GWIDTH - 1, 511);
  146.     {
  147.         int i;
  148.  
  149.         for (i = WIN_SY - 2; i <= 29; i++) {
  150.             p_lin(lp + i, i);
  151.         }
  152.     }
  153.  
  154.     /*
  155.     !    マウスなど離されるの待ち
  156.     */
  157.     wait_mb_off();
  158.  
  159. }
  160.  
  161. /*
  162.     メッシュ処理をするですのところ
  163.     ようするに描く場所なわけだ
  164.  
  165.     flagのビット0がオンなら縦線、
  166.     ビット1がオンなら横線を引く。(両方オンなら両方引く)
  167. */
  168. static void 
  169. mesh_exec(short x_style, short y_style, short flag)
  170. {
  171. #define        SX    0    /* Start */
  172. #define        SY    16
  173. #define        EX    (GWIDTH-1)    /* End */
  174. #define        EY    495
  175. #define        OX    8    /* Offset */
  176. #define        OY    16
  177.  
  178.  
  179. #define        FRONT_COLOR    0    /* バックのパレット番号 */
  180. #define        BACK_COLOR    2    /* 線のパレット番号 */
  181.  
  182.  
  183.     int x, y;
  184.  
  185.     if (flag & 0x1) {    /* 縦線 */
  186.         for (x = SX; x < EX; x += OX) {
  187.             line(x, SY, x, EY, FRONT_COLOR, 0xffff);    /* まず消す */
  188.             if (x_style) {
  189.                 line(x, SY, x, EY, BACK_COLOR, x_style);
  190.             }
  191.         }
  192.     }
  193.     if (flag & 0x2) {    /* 横線 */
  194.         for (y = SY + 15; y < EY + 15; y += OY) {
  195.             line(SX, y, EX, y, FRONT_COLOR, 0xffff);    /* まず消す */
  196.             if (y_style) {
  197.                 line(SX, y, EX, y, BACK_COLOR, y_style);
  198.             }
  199.         }
  200.     }
  201. }
  202.  
  203. /* [ EOF ] */
  204.